package com.example.administrator.fastdream.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.fastdream.R;
import com.example.administrator.fastdream.view.base.BaseActivity;
import com.example.administrator.fastdream.date.utils.MyUtils;
import com.example.administrator.fastdream.date.utils.SendSmsTimerUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ConfirmCardInfoActivity extends BaseActivity {

    @BindView(R.id.iv_mine)
    ImageView ivMine;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.tv_bank)
    TextView tvBank;
    @BindView(R.id.tv_cardtype)
    TextView tvCardtype;
    @BindView(R.id.et_phone)
    EditText etPhone;
    @BindView(R.id.et_code)
    EditText etCode;
    @BindView(R.id.tv_sendcode)
    TextView tvSendcode;
    @BindView(R.id.tv_yes)
    TextView tvYes;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_confirm_card_info);
        ButterKnife.bind(this);
        ivBack.setVisibility(View.VISIBLE);
        tvTitle.setText("确认信息");
    }

    @OnClick({R.id.iv_back, R.id.tv_sendcode, R.id.tv_yes})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_sendcode:
                getCode();
                break;
            case R.id.tv_yes:
                confirmInfo();
                break;
        }
    }

    private void confirmInfo() {
        String phone = etPhone.getText().toString().trim();
        String code = etCode.getText().toString().trim();
        if (TextUtils.isEmpty(phone)) {
            Toast.makeText(this, "请输入手机号", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!MyUtils.isMobileNO(phone)) {
            Toast.makeText(this, "请正确格式的手机号", Toast.LENGTH_SHORT).show();
            return;
        }
        if (TextUtils.isEmpty(code)) {
            Toast.makeText(this, "请输入验证码", Toast.LENGTH_SHORT).show();
            return;
        }
        startActivity(new Intent(this,JoinActivity.class));
    }

    private void getCode() {
        String phone = etPhone.getText().toString().trim();
        if (TextUtils.isEmpty(phone)) {
            Toast.makeText(this, "请输入手机号", Toast.LENGTH_SHORT).show();
            return;
        }
        if (!MyUtils.isMobileNO(phone)) {
            Toast.makeText(this, "请正确格式的手机号", Toast.LENGTH_SHORT).show();
            return;
        }
        SendSmsTimerUtils.sendSms(tvSendcode, R.color.white, R.color.white);
    }
}
